<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>仕様書チェッカー</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>


<body>
<form>
<input type="file" id="file" />
</form>

<div id="outputName"></div>
<div id="outputContents">URI</div>

<script type="text/javascript">

	if (window.File) {
	} else {
		alert('window.File are not supported in this browser.');
	}
	if (window.FileReader) {
	} else {
		alert('window.FileReader are not supported in this browser.');
	}
	if (window.FileList) {
	} else {
		alert('window.FileList are not supported in this browser.');
	}
	if (window.Blob) {
	} else {
		alert('window.Blob are not supported in this browser.');
	}

	if (window.File && window.FileReader && window.FileList && window.Blob) {
		// Great success! All the File APIs are supported.
		//	alert('The File APIs are fully supported in this browser.');
	}

	document.getElementById('file').addEventListener('change', handleFileSelect, false);

	function handleFileSelect(evt) {
		var file = evt.target.files[0];
//		alert(file);
		var output = [];
		output.push('<li><strong>', escape(file.name), '</strong></li>');
		document.getElementById('outputName').innerHTML = '<ul>' + output.join('') + '</ul>';

		textReader(file);

	}
	function textReader(file){
		var reader = new FileReader();

		reader.readAsText(file, "utf-8");
//		document.getElementById('outputContents').innerHTML = reader.result;
		reader.onloadend = function (e) {
			alert(document.getElementById('outputContents'));
			document.getElementById('outputContents').innerHTML = e.target.result;
		};
		reader.onerror = error;
	}
	function loaded (e) {
		alert(document.getElementById('outputContents'));
		document.getElementById('outputContents').innerHTML = this.result;
	}
	function error(evt) {
		alert(this);
	    if (evt.target.error.code == evt.target.error.NOT_READABLE_ERR) {
	        alert("ファイルが読めません！");
	    }
	}
// 	reader.onerror = function(e) {
// 			switch (e.target.error.code) {
// 			case 1:
// 				text.innerHTML = "NOT_FOUND_ERROR!";
// 				break;
// 			case 2:
// 				text.innerHTML = "SECURITY_ERROR!";
// 				break;
// 			case 3:
// 				text.innerHTML = "ABORT_ERROR!";
// 				break;
// 			case 4:
// 				text.innerHTML = "NOT_READABLE_ERROR!";
// 				break;
// 			case 5:
// 				text.innerHTML = "ENCODING_ERROR!";
// 				break;
// 			default:
// 				text.innerHTML = "Unknown ERROR!";
// 			}
// 		}



</script>
</body>
</html>